﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

using Xamarin.Forms;

namespace SharedMobilePlatform
{
	public class SelectPage : RaspContentPage
	{
	    public ProgressBar progressBar;

	    public List<string> dekaederCharacters;

	    private ListView listView;

		public SelectPage (string raspnamn)
		{
            progressBar = new ProgressBar()
            {
                Progress = 0.2
            };
            dekaederCharacters = new List<string>();

            progressBar.ProgressTo(.8, 30000, Easing.Linear);

            listView = new Xamarin.Forms.ListView()
            {
                RowHeight = 60,
                ItemsSource = dekaederCharacters,
                
            };

		    listView.ItemTapped += ((sender, e) => showMessage(sender, e));
			Content = new StackLayout {
				Children = {
                    progressBar,
					listView
				}
			};

            _client.GetMyDekaederCharacterListAsync(raspnamn);
		}


	    public override void InitializeWcfServiceClient()
	    {
            _client.GetMyDekaederCharacterListCompleted += UpdateCharacters;
	    }

        private void UpdateCharacters(object sender, GetMyDekaederCharacterListCompletedEventArgs e)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                progressBar.IsVisible = false;
                if (!e.Cancelled)
                {
                    dekaederCharacters = e.Result.ToList();
                    listView.ItemsSource = dekaederCharacters;
                }
            });
            
        }

	    public void showMessage(object sender, EventArgs args)
	    {
	        
	    }

	}
}
